package deployr.core;

import java.util.*;
import java.util.regex.*;

public class Breadcrumbs {
	public static final Breadcrumbs fromPathOrPackage(String sep, String path) {
		return fromPathOrPackage("", sep, path);
	}

	public static Breadcrumbs fromPathOrPackage(String prefix, String sep, String path) {
		Breadcrumbs breadcrumbs = new Breadcrumbs(prefix, sep);

		Scanner scanner = new Scanner(path).useDelimiter(Pattern.compile("/"));
		while (scanner.hasNext()) {
			String token = scanner.next();
			breadcrumbs.add(token);
		}

		return breadcrumbs;
	}

	private List<String> tokens = new LinkedList<String>();

	private final String prefix;

	private final String sep;

	public Breadcrumbs() {
		this("", "/");
	}

	public Breadcrumbs(String prefix, String sep) {
		this.prefix = prefix;
		this.sep = sep;
	}

	public void add(String node) {
		tokens.add(node);
	}

	public String prefix() {
		return prefix;
	}

	public String sep() {
		return sep;
	}

	public Iterable<String> tokens() {
		return tokens;
	}

}
